package com.lyh.hkcloud.adapter;

import android.content.Context;
import android.view.View;
import com.lyh.hkcloud.R;
import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import com.lyh.hkcloud.base.*;
import com.lyh.hkcloud.constants.*;
import com.lyh.hkcloud.util.base.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;

public class GridViewMainAdapter extends BaseJsonViewAdapter<GridViewMainAdapter.ViewHolder> {


    public GridViewMainAdapter(Context context, JSONArray list) {
        super(context, list);
    }

    @Override
    protected int getItemResuId() {
        return R.layout.activity_main_gridview_item;
    }

    @Override
    protected void initItem(int position,ViewHolder holder, View v, JSONObject obj) {
        holder.imageView = v.findViewById(R.id.iv_logo);
        holder.textView = v.findViewById(R.id.tv_title);
    }

    @Override
    protected void setItem(int position,ViewHolder holder, JSONObject obj) {
        String imageUrl = UrlConstants.convertFullUrl(obj.optString("imageUrl").trim());
        if (StringUtils.isNotEmpty(imageUrl)) {
            holder.imageView.setImageURI(imageUrl);
        }
        String text = obj.optString("appName");
        holder.textView.setText(text);
    }

   public static class ViewHolder {
        SimpleDraweeView imageView;
        TextView textView;

    }
}

